<?php

class ProductosController extends AppController {
    public $helpers = array('Html', 'Form');
    public $name = 'Productos';
    
    public function index() {
        $this->set('productos', $this->Producto->find('all'));
    }
    
    public function add() {
        $this->set('categorias', $this->Producto->Categoria->find('list', array(
            'fields' => array('Categoria.id', 'Categoria.categoria')
        )));
        
        if($this->request->is('post') && isset($this->data)) {
            if($this->Producto->save($this->data)) {
                $this->redirect(array('action' => 'index'));
            }
        }
    }
    
    public function edit($id = null) {        
        $this->set('categorias', $this->Producto->Categoria->find('list', array(
            'fields' => array('Categoria.id', 'Categoria.categoria')
        )));
        
        if($this->request->is('post')) {           
            if($this->Producto->save($this->data)) {
                $this->redirect(array('action' => 'index'));
            }
        }
        
        $this->set('producto', $this->Producto->findById($id));             
    }
}

?>
